package com.xiang.publicdemo.module1.config;

import com.xiang.publicdemo.module1.listener.MyHttpSessionListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.SessionEventHttpSessionListenerAdapter;

import javax.servlet.http.HttpSessionListener;
import java.util.ArrayList;
import java.util.List;

@Configuration
//maxInactiveIntervalInSeconds 默认是1800秒过期，这里测试修改为60秒
@EnableRedisHttpSession(maxInactiveIntervalInSeconds=180)
public class RedisHttpSessionConfig{

    @Bean
    public SessionEventHttpSessionListenerAdapter getSessionEventHttpSessionListenerAdapter(){
        List<HttpSessionListener> listeners = new ArrayList<>();
        listeners.add(getHttpSessionListener());
        return new SessionEventHttpSessionListenerAdapter(listeners);
    }

    @Bean
    public HttpSessionListener getHttpSessionListener(){
        return new MyHttpSessionListener();
    }
}